import 'package:flutter/material.dart';
import 'package:flutter_base_app/config/app_colors.dart';
import 'package:flutter_base_app/generated/assets.dart';
import 'package:flutter_base_app/widgets/image/svg_widget.dart';

class LineItemWidget extends StatelessWidget {
  final String icon;
  final String title;
  final String subTitle;
  final bool showArrow;
  final double height;
  final Widget? left;
  final Widget? center;
  final Widget? subTitleWidget;
  final VoidCallback? onTap;

  const LineItemWidget({
    super.key,
    this.icon = "",
    this.title = "",
    this.subTitle = "",
    this.showArrow = true,
    this.height = 45,
    this.left,
    this.center,
    this.subTitleWidget,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: onTap,
      child: Container(
        height: height,
        padding: const EdgeInsets.symmetric(horizontal: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            //左边
            if (left != null || icon.isNotEmpty)
              SizedBox(
                height: height,
                child: left ?? SvgWidget(icon),
              ),
            //中间
            Expanded(
              child: Container(
                height: height,
                alignment: Alignment.centerLeft,
                margin: EdgeInsets.symmetric(horizontal: 10),
                child: center ??
                    Text(
                      title,
                      style: TextStyle(fontSize: 18, color: Colors.black),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
              ),
            ),
            //右边
            if (subTitleWidget != null || subTitle.isNotEmpty)
              Container(
                height: height,
                alignment: Alignment.centerLeft,
                margin: EdgeInsets.only(right: 5),
                child: subTitleWidget ??
                    Text(
                      subTitle,
                      style: TextStyle(fontSize: 18, color: ColorsApp.gray_92),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
              ),
            //箭头
            if (showArrow) SvgWidget(Assets.svgMainIcArrowRight),
          ],
        ),
      ),
    );
  }
}
